package org.example.sboot;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @author jia
 * @date 2021/4/25
 */

@SpringBootApplication
@MapperScan("org.example.sboot.mapper")
public class SbootApplication extends WebMvcConfigurationSupport {

    public static void main(String[] args) {
        SpringApplication.run(SbootApplication.class, args);
        System.out.println("系统启动成功～(￣▽￣～)(～￣▽￣)～");
    }

    @Override
    //这里配置静态资源文件的路径导包都是默认的直接导入就可以
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        /** 本地文件上传路径 */
        //因为有这一句，templates目录下的静态资源才能被加载，适用非标准目录
        registry.addResourceHandler("/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/templates/");
        //因为有这一句，static目录下的静态资源才能被加载，适用标准目录
        registry.addResourceHandler("/templates/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/templates/");
        registry.addResourceHandler("/statics/**")
                .addResourceLocations("classpath:/statics/");
        registry.addResourceHandler("/swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }
}
